import 'package:flutter/material.dart';

class CustomSelection extends StatelessWidget {
  bool? required = false;
  String label;
  TextStyle? labelStyle;
  String? value;
  TextStyle? valueStyle;
  String? hintText;
  bool enable;
  List<Widget>? rightAction;
  Function? onPressed;
  Alignment? align;
  TextAlign? textAlign;

  CustomSelection(
    this.label, {
    super.key,
    this.required,
    this.labelStyle,
    this.value,
    this.valueStyle,
    this.rightAction,
    this.hintText,
    this.enable = true,
    this.onPressed,
    this.align = Alignment.centerRight,
    this.textAlign = TextAlign.right,
  });

  @override
  Widget build(BuildContext context) {
    List<Widget> list = [];
    if (required == true) {
      list.add(const SizedBox(
        width: 10,
        child: Center(
          child: Text(
            "*",
            style: TextStyle(
              fontSize: 15,
              color: Color(0xFFFF685C),
            ),
          ),
        ),
      ));
    } else {
      // list.add(const SizedBox(
      //   width: 16,
      // ));
    }
    list.add(Text(
      label.trim(),
      style:
          labelStyle ?? const TextStyle(color: Color(0xff666666), fontSize: 15),
    ));
    list.add(const SizedBox(
      width: 8,
    ));
    List<Widget> inputList = [];
    if (value?.isNotEmpty == true) {
      inputList.add(Expanded(
          child: Container(
        padding: const EdgeInsets.only(top: 8, bottom: 8),
        alignment: align,
        constraints: const BoxConstraints(minHeight: 48),
        child: Text(
          value!,
          textAlign: TextAlign.right,
          style: valueStyle ??
              const TextStyle(color: Color(0xff333333), fontSize: 15),
        ),
      )));
    } else {
      inputList.add(Expanded(
          child: Container(
        padding: const EdgeInsets.only(top: 8, bottom: 8),
        alignment: Alignment.centerRight,
        constraints: const BoxConstraints(minHeight: 48),
        child: Text(
          hintText ?? "请选择$label",
          style: const TextStyle(color: Colors.grey, fontSize: 15),
        ),
      )));
    }

    inputList.add(const SizedBox(
      width: 8,
    ));
    if (rightAction?.isNotEmpty == true) {
      rightAction?.forEach((element) {
        inputList.add(element);
      });
    } else {
      inputList.add(const SizedBox(
        width: 32,
        height: 32,
        child: Icon(
          Icons.keyboard_arrow_right,
          color: Color(0xffC6C6C6),
        ),
      ));
    }

    list.add(Expanded(
        child: GestureDetector(
      onTap: () {
        if (enable) {
          FocusManager.instance.primaryFocus?.unfocus();
          onPressed?.call();
        }
      },
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 3),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: inputList,
        ),
      ),
    )));

    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: list,
    );
  }
}
